package com.stars.home.activity

import android.os.Bundle
import android.webkit.WebView
import com.qmuiteam.qmui.widget.webview.QMUIWebViewClient
import com.stars.home.base.MBActivity
import com.stars.home.databinding.ActivityWebviewBinding
import com.trailer.base.base.BRepository
import com.trailer.base.base.BViewModel

open class WebViewActivity : MBActivity<BViewModel<BRepository>, ActivityWebviewBinding>() {

    override fun init(savedInstanceState: Bundle?) {
        super.init(savedInstanceState)


        binding.webView.webViewClient = MyWebViewClient()
        val settings = binding.webView.settings
        settings.javaScriptEnabled = true
        var type=intent?.extras?.getString("type")
        var url=""
        if(type.equals("1")){//用户协议
            url="tc.huaxiutang.cn/h5/index/yhxy"
        }
        if(type.equals("2")){//隐私协议
            url="tc.huaxiutang.cn/h5/index/yhxy"
        }
        binding.webView.loadUrl(url)


    }

    override fun binding(): ActivityWebviewBinding {
        return ActivityWebviewBinding.inflate(layoutInflater)
    }

    override fun onDestroy() {
        binding.webView.destroy()
        super.onDestroy()
    }


    private class MyWebViewClient : QMUIWebViewClient(true, false) {

        override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean {
//            if (Uri.parse(url).host == "www.example.com") {
            // This is my web site, so do not override; let my WebView load the page
            return false
//            }
            // Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
//            Intent(Intent.ACTION_VIEW, Uri.parse(url)).apply {
//                startActivity(this)
//            }
//            return true
        }
    }

}
